<?php

  /**
    *
    * FILE:          community_totals_list.php
    * LOCATION:      /root
    * REFERENCES:    none 
    * FUNCTION:          
    * DEPENDENCIES: 
    *
    * ==============================================================================
    * 
    * @version $Id: nav.php,v 0.1 2007/09/3
    * @copyright Copyright (c) none
    * @author chrisv
    * @license http://opensource.org/licenses/gpl-license.php GNU General 
    * Public License (GPL)
    * 
    * ==============================================================================
    * 
    */
   //connect to database
	include('./includes/db_connect.php');
	include_once('./classes/pagination.class.php');
       

   if($_GET["Status"]) {
    
?>
      <p class="alert2"><?php echo $_GET["Status"]; ?></p>

<?php 

   }
   
	  
    //main pagination settings
	$items = 10;
	$page = 1;


	 //BEGIN PAGINATION CODE
     //THIS BLOCK HANDLES EMPTY SEARCH STRING
     if(isset($_GET['page']) and is_numeric($_GET['page']) and $page = $_GET['page']){
			$limit = " LIMIT ".(($page-1)*$items).",$items";
     }else{
			$limit = " LIMIT $items";
     }

	 //$sqlStr = "SELECT * FROM consumer";

				/*
              $sqlStr = "SELECT c.id, 
                                c.last_name, 
                                c.first_name, 
                                c.city, 
                                c.phone, 
                                c.address, 
                                c.zip, 
                                c.phone, 
                                ls.name as state
                          FROM   consumer c, 
                                 lst_state ls 
                          WHERE  c.state_id = ls.id 
                          ORDER BY c.last_name asc";

	      $sqlStrAux = "SELECT count(*) as total FROM consumer";
			*/
			 /*
			              $sqlStr = "SELECT ct.CT_id, 
                                ct.CT_Coordinator_Name, 
                                ct.CT_Month, 
                                ct.CT_Year, 
                                ct.CT_Contacts, 
                                ct.CT_Service_Hours_Total
                          FROM  community_totals ct
															WHERE CT_Coordinator_Name = '".$loggedIn."'
                          ORDER BY ct.CT_id desc";
			*/
													
					if($loggedInUserID == 2 || $loggedInUserID == 5 || $loggedInUserID == 10 ){
			              
										$sqlStr = "SELECT ct.CT_id, 
                                ct.CT_Coordinator_Name, 
                                ct.CT_Month, 
                                ct.CT_Year, 
                                ct.CT_Contacts, 
                                ct.CT_Service_Hours_Total
                          FROM  community_totals ct
                          ORDER BY ct.CT_id desc";
													
													
									$sqlStrAux = "SELECT count(*) as total 
																	 FROM community_totals";
					
					}else{
					
			              $sqlStr = "SELECT ct.CT_id, 
                                ct.CT_Coordinator_Name, 
                                ct.CT_Month, 
                                ct.CT_Year, 
                                ct.CT_Contacts, 
                                ct.CT_Service_Hours_Total
                          FROM  community_totals ct
															WHERE CT_Coordinator_Name = '".$loggedIn."'
                          ORDER BY ct.CT_id desc";
													
													
									$sqlStrAux = "SELECT count(*) as total 
																	 FROM community_totals
																	WHERE CT_Coordinator_Name = '".$loggedIn."'";
					}
					
	      $aux = Mysql_Fetch_Assoc(mysql_query($sqlStrAux));
		  
	      $query = mysql_query($sqlStr.$limit);

				if($loggedInUserID == 2 || $loggedInUserID == 5 || $loggedInUserID == 10 ){
         echo "<span id=\"records_indicator\">".$aux['total']."</span> 
               <h2>Community Totals Reocords were found in the database.";
				}else{
				  echo "<span id=\"records_indicator\">".$aux['total']."</span> 
               <h2>Community Totals Reocords were found in the database created by <br /><br />
									<span id=\"highlightCoordinator\">".$loggedIn."</span></h2>";
				}

	      if($aux['total']>0){
			$p = new pagination;
			$p->Items($aux['total']);
			$p->limit($items);
			$p->target("admin.php?action=community_totals_list");
			$p->currentPage($page);
			$p->calculate();
			$p->changeClass("pagination");

	
?>
          <!-- SET UP TABLE  FOR FULL RESULTSET-->
          <table class="table2">
                   <thead> 
                      <tr>
                         <th>Community Total Record ID</th>
                         <th>Record Created By</th>
                         <th>Record Month</th>
                         <th>Record Year</th>
                         <th>Total Contacts For Record</th>
                         <th>Total Service Hours For Record</th>
                     </tr>
                  </thead>
                  <tbody>
<?php

         while($row = mysql_fetch_assoc($query)){
	  
                        if($i%2==0) {
		 
                          echo "<tr class='even'>";
	
                        }else {
	    
                          echo "<tr class='odd'>";
	      
                        }
?>

                        <!-- USER CAN CLICK ON ANY TABLE COLUMN TO GET CT RECORD-->
                        <td>
                            <a href="admin.php?action=community_totals&CT_id=<?php echo $row["CT_id"]; ?>">
                                 <?php echo "<h2><span class=\" link\">#".$row['CT_id']."</h2>"; ?>
                            </a>
                        </td>
                        <td>
				<a href="admin.php?action=community_totals&CT_id=<?php echo $row["CT_id"]; ?>">
				<?php echo $row["CT_Coordinator_Name"]; ?>
				</a>
			</td>
                        <td style="text-align: center;"><?php echo $row["CT_Month"]; ?></td>
                        <td style="text-align: center;"><?php echo $row["CT_Year"]; ?></td>
                        <td style="text-align: center;"><?php echo $row["CT_Contacts"]; ?></td>
                        <td style="text-align: center;"><?php echo $row["CT_Service_Hours_Total"]; ?></td>
                   </tr>
                </tbody>

<?php

                $i++;
             
              }  //END WHILE recordset fetch
?>
              </table>
              <!-- END RESULTSET TABLE -->
<?php

	      $p->show();

         }else{
		echo "There no are records to paginate.";
         } //ENDS routine for EMPTY SEARCH STRING

?>
   <br/>

<!-- USER HAS OPTION TO CREATE NEW CONSUMER CASE FILE -->
<p style="text-align:right;">
	<a style="border-top:1px #ccc dotted" href="admin.php?action=community_totals&id=0"><strong>Create New Community Totals Record</strong></a>
</p>
</p>